local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
local __TS__SourceMapTraceBack = ____lualib.__TS__SourceMapTraceBack
__TS__SourceMapTraceBack(debug.getinfo(1).short_src, {["7"] = 3,["8"] = 3,["9"] = 9,["10"] = 9,["11"] = 9,["12"] = 62,["13"] = 62,["14"] = 62,["15"] = 62,["16"] = 14,["17"] = 26,["18"] = 32,["19"] = 37,["20"] = 43,["21"] = 49,["22"] = 55,["23"] = 62,["24"] = 69,["25"] = 70,["26"] = 70,["27"] = 69,["28"] = 77,["29"] = 78,["30"] = 77,["31"] = 86,["32"] = 87,["33"] = 88,["34"] = 86,["35"] = 95,["36"] = 96,["37"] = 97,["38"] = 95,["39"] = 104,["40"] = 105,["41"] = 105,["42"] = 106,["43"] = 104,["44"] = 113,["45"] = 114,["46"] = 114,["47"] = 115,["48"] = 113,["49"] = 121,["50"] = 122,["51"] = 122,["52"] = 123,["53"] = 123,["54"] = 123,["55"] = 124,["56"] = 125,["57"] = 126,["58"] = 127,["60"] = 129,["61"] = 129,["62"] = 129,["63"] = 129,["64"] = 123,["65"] = 123,["66"] = 131,["67"] = 132,["68"] = 132,["69"] = 132,["70"] = 132,["71"] = 133,["73"] = 122,["74"] = 122,["75"] = 122,["76"] = 121,["77"] = 143,["78"] = 144,["79"] = 145,["81"] = 147,["82"] = 143});
local ____exports = {}
local ____unit = require("kernel.util.unit")
local KUnit = ____unit.default
____exports.default = __TS__Class()
local RectAttack = ____exports.default
RectAttack.name = "RectAttack"
function RectAttack.prototype.____constructor(self, player, monsterId, monsterCount)
    self.player = player
    self.monsterId = monsterId
    self.monsterCount = monsterCount
    self.isRandom = false
    self.monsterInterval = 1
    self.timerId = 0
    self.monsterNumber = 0
    self.rects = {}
    self.endCallbacks = {}
    self.refreshCallbacks = {}
end
function RectAttack.prototype.addRect(self, rect)
    local ____self_rects_0 = self.rects
    ____self_rects_0[#____self_rects_0 + 1] = rect
end
function RectAttack.prototype.setIsRandom(self, value)
    self.isRandom = value
end
function RectAttack.prototype.setTarget(self, x, y)
    self.target = Fix32Vec3(x, y, 0)
    return self
end
function RectAttack.prototype.setMonsterInterval(self, value)
    self.monsterInterval = value
    return self
end
function RectAttack.prototype.onEnd(self, callback)
    local ____self_endCallbacks_1 = self.endCallbacks
    ____self_endCallbacks_1[#____self_endCallbacks_1 + 1] = callback
    return self
end
function RectAttack.prototype.onRefresh(self, callback)
    local ____self_refreshCallbacks_2 = self.refreshCallbacks
    ____self_refreshCallbacks_2[#____self_refreshCallbacks_2 + 1] = callback
    return self
end
function RectAttack.prototype.start(self)
    self.timerId = setInterval(
        function()
            __TS__ArrayForEach(
                self.rects,
                function(____, rect)
                    local point = self:getRefreshPoint(rect)
                    local unit = KUnit:create(self.player, self.monsterId, point)
                    if self.target then
                        unit:releaseCommand("attackMove", self.target)
                    end
                    __TS__ArrayForEach(
                        self.refreshCallbacks,
                        function(____, call) return call(nil, unit, point) end
                    )
                end
            )
            if self.monsterNumber >= self.monsterCount then
                __TS__ArrayForEach(
                    self.endCallbacks,
                    function(____, callback) return callback(nil) end
                )
                clearInterval(self.timerId)
            end
        end,
        self.monsterInterval * 1000
    )
end
function RectAttack.prototype.getRefreshPoint(self, rect)
    if self.isRandom then
        return rect:random()
    end
    return rect:center()
end
return ____exports
